package com.twu.biblioteca.controllers;

import com.twu.biblioteca.db.Database;
import com.twu.biblioteca.models.User;

public class UserController {
    private User currentUser = null;
    private Database database;

    public UserController(Database database) {
        this.database = database;
    }

    public String authenticate(String login, String password) {
        User user = database.getUserByLogin(login);
        if (user != null) {
            if (user.getLogin().equals(login)) {
                if (user.authenticate(password)) {
                    this.currentUser = user;
                    return "Hello, " + user.getName();
                }
            }
        }
        return "Invalid login or password.";
    }

    public User getCurrentUser() {
        return currentUser;
    }
}
